define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'task/flower/index',
                    add_url: 'task/flower/add',
                    edit_url: 'task/flower/edit',
                    del_url: 'task/flower/del',
                    multi_url: 'task/flower/multi',
                    table: 'shop_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'order_id',
                sortName: 'order_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'task_sno', title: __('任务编号')},
                        {field: 'order_sno', title: __('订单编号')},
                        {field: 'room', title: __('所属房间')},
                        {field: 'o.shop_name', title: __('店铺名称'),operate:"LIKE"},
                        {field: 'real_money', title: __('订单收费'),formatter:function(value,row,index){
                                // var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                // var index = keys.indexOf(value.toString());
                                // value = value === null ? '' : value.toString();
                                // var display = index > -1 ? this.searchList[value] : null;
                                // var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                // if (!display) {
                                //     display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                // }
                                var html = '<span class="text">' + 1.5 + '</span>';

                                return html;
                            }},
                        {field: 'platform_type', title: __('所属平台'),searchList: {
                                "1":__('天猫'),
                                "2":__('淘宝'),
                                "3":__('不限')
                            },formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                var index = keys.indexOf(value.toString());
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            }},
                        {field: 'tao_bao_no', title: __('淘宝号')},
                        {field: 'o.create_time', title: __('接单时间'),operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'o.status', title: __('Status'),searchList: {
                                "0":__('已拍下'),
                                "1":__('未审核'),
                                "13":__('已完成'),
                        },formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                if(value=="" || value==null){
                                    value = value;
                                }else{
                                    value = value.toString();
                                }
                                if(value==0){
                                    value = "0";
                                }
                                var index = keys.indexOf(value);
                                console.log(value);
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            },operate:false},
                        {field: 'is_cancel', title: __('是否取消'),searchList: {
                                "1":__('否'),
                                "2":__('是')
                            },formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                var index = keys.indexOf(value.toString());
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            }},
                        {field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            formatter: function (value, row, index) {
                            var table = this.table;
                            // 操作配置
                            var options = table ? table.bootstrapTable('getOptions') : {};
                            // 默认按钮组
                            var buttons = $.extend([], this.buttons || []);
                            console.log(row["o.status"]);
                            if (options.extend.edit_url !== '') {
                                buttons.push({
                                    name: 'edit',
                                    icon: 'fa fa-pencil',
                                    title: __('Edit'),
                                    text:"查看",
                                    extend: 'data-toggle="tooltip"',
                                    classname: 'btn btn-xs btn-success btn-editone',
                                    url: options.extend.edit_url
                                });
                            }
                            $(table).data("operate-del", null);
                            return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
                        }}

                    ]
                ]
            });




            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});